<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head >
<meta charset="utf-8">
<title>授权用户</title> 
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
<link rel="stylesheet" href="../../../layuiadmin/layui/css/layui.css"  media="all"/>
<link rel="stylesheet" href="../../../layuiadmin/style/admin.css" media="all"/>
<link rel="stylesheet"  href="../../../css/common/loader.css" media="all"/>
<link rel="stylesheet"  href="../../../css/common/tablepage.css" media="all"/>
<link rel="stylesheet"    href="../../../lib/ztree/css/zTreeStyle/zTreeStyle.css" type="text/css" media="all">
</head>
<body>

	<div class="layui-fluid">
		<div class="layui-row layui-col-space1">
			<!-- <div class="layui-col-md3" >
				<div class="layui-card" style="overflow: auto;height: 100%;" >
					<div class="layui-card-header">组织机构树</div>
					<div class="layui-card-body">
						<ul id="ztree" class="ztree"></ul>
					</div>
				</div>
			</div> -->
			<div class="layui-col-md6">
				<div class="layui-card">
					<div class="layui-form layui-card-header layuiadmin-card-header-auto"
						id="searchForm">
						<div class="layui-form-item">
							<input type="hidden" id="outRoleId" name="outRoleId"  />
							<input type="hidden" id="cascadeId" name="cascadeId"  />
							<div class="layui-inline">
								<label class="layui-form-label">查询条件</label>
								<div class="layui-input-block">
									<input type="text" name="queryParam" placeholder="账号或用户名"
										autocomplete="off" class="layui-input">
								</div>
							</div>
							<div class="layui-inline">
								<button class="layui-btn layuiadmin-btn-sm" lay-submit
									lay-filter="searchSubmit">查询</button>

							</div>

						</div>
					</div>
					<div class="layui-card-body">
						<table id="dataList" lay-filter="dataList"></table>


					</div>
				</div>
			</div>
			<div class="layui-col-md6">
			<div class="layui-card">
					<div class="layui-form layui-card-header layuiadmin-card-header-auto"
						id="roleUserForm">
						<div class="layui-form-item">
							<input type="hidden" id="inRoleId" name="inRoleId" />
							<div class="layui-inline">
								<label class="layui-form-label">查询条件</label>
								<div class="layui-input-block">
									<input type="text" name="queryParam" placeholder="账号或用户名"
										autocomplete="off" class="layui-input">
								</div>
							</div>
							<div class="layui-inline">
								<button class="layui-btn layuiadmin-btn-sm" lay-submit
									lay-filter="roleUserSubmit">查询</button>

							</div>

						</div>
					</div>
					<div class="layui-card-body">
						<table id="roleUserList" lay-filter="roleUserList"></table>


					</div>
				</div>
			</div>
		</div>
	</div>
		<script type="text/html" id="trTool">
    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="auzUser"><i class="layui-icon layui-icon-auz"></i>授权</a>
</script>
		<script type="text/html" id="roleUserTool">
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="remove"><i class="layui-icon layui-icon-delete"></i>移除</a>
</script>
		<script type="text/html" id="toolbar">
  <div class="layui-btn-container">
    <button class="layui-btn layui-btn-sm" lay-event="batchAuzUser"> <i class="layui-icon" >&#xe654;</i>批量授权</button>
  </div>
</script>
		<script type="text/html" id="roleUserToolbar">
  <div class="layui-btn-container">
    
    <button class="layui-btn layui-btn-danger layui-btn-sm" lay-event="batchRemove"> <i class="layui-icon layui-icon-delete"></i>批量移除授权</button>
  </div>
</script>
	<script type="text/javascript" src="../../../layuiadmin/layui/layui.js"></script>
   <script type="text/javascript" src="../../../lib/jQuery-2.2.0.min.js" ></script>
	<script type="text/javascript" src="../../../lib/ztree/js/jquery.ztree.core.js"></script>
	<script type="text/javascript" src="../../../lib/ztree/js/jquery.ztree.excheck.js"></script>
	<script type="text/javascript" src="../../../lib/ztree/js/jquery.ztree.exedit.js"></script>
	<script>
	layui.config({
		base :  '../../../layuiadmin/' //静态资源所在路径
	}).extend({
		webplus : 'lib/webplus' //主入口模块
	}).use([ 'table', 'form','webplus' ], function() {
		var $ = layui.$, 
		form = layui.form, 
		table = layui.table,
		webplus=layui.webplus;
		var roleId=webplus.getUrlType().id;
		$("#outRoleId").val(roleId);
		$("#inRoleId").val(roleId);
		
		 var cols= [ [{
				checkbox: true
			}, {
				field : 'userId',
				title : '编号',
				hide : true 
			}, {
				field : 'account',
				title : '用户账号',
				minWidth : 90
			}, {
				field : 'username',
				title : '姓名',
				minWidth : 80
			}, {

				title : '操作',
				toolbar : '#trTool',
				width : 83,
				fixed: 'right'
			} ] ];
	   var params={};
	   params.outRoleId=roleId;
	   webplus.init('system/user/list',cols,'','','','','',params,);
	   
	   var roleCols= [ [ {
			checkbox: true
		}, {
			field : 'userId',
			title : '编号',
			hide : true 
		}, {
			field : 'account',
			title : '用户账号',
			minWidth : 90
		}, {
			field : 'username',
			title : '姓名',
			minWidth : 80
		}, {

			title : '操作',
			toolbar : '#roleUserTool',
			width : 83,
			fixed: 'right'
		} ] ];
	 var roleParams={}
	 roleParams.inRoleId=roleId;
     webplus.init('system/user/list',roleCols,'roleUserForm','roleUserSubmit','roleUserList','roleUserToolbar','roleUserTool', roleParams);
			 //监听行工具事件
			  table.on('tool(dataList)', function(rowObj){
			   
			    switch(rowObj.event){
			    	
			    	case 'auzUser':
			    		var paramData = {};
			    		paramData.userIds=rowObj.data.userId;
			    		paramData.roleId=roleId;
			    		webplus.doAjax('system/role/saveRoleUser',paramData,'','','0');
			    		break;
			    }
			    return false;
			  
			  });
			 
			 
			 //监听表头按钮事件
			  table.on('toolbar(dataList)', function(obj){
			    switch(obj.event){
			      	case 'batchAuzUser':
			        var paramData = {};
		    		paramData.roleId=roleId;
			      	webplus.batchOperate('system/role/saveRoleUser','','userId','userIds',paramData,'你确定批量授权你选择的用户吗？');
			     	     break;
			      
			    }
			  });
			   
			  //监听行工具事件
			  table.on('tool(roleUserList)', function(rowObj){
			    switch(rowObj.event){
			    	
			    	case 'remove':
			    		var paramData = {};
			    		paramData.userIds=rowObj.data.userId;
			    		paramData.roleId=roleId;
			    		webplus.doAjax('system/role/removeRoleUser',paramData,'你确定撤销这个用户授权吗？','','0');
				        
			    		break;
			    }
			    
			  });
			 
			 
			 //监听表头按钮事件
			  table.on('toolbar(roleUserList)', function(obj){
			    switch(obj.event){
			      
			      	case 'batchRemove':
			      		var paramData = {};
				    	paramData.roleId=roleId;
					    webplus.batchOperate('system/role/removeRoleUser','roleUserList','userId','userIds',paramData,'你确定批量移除授权的用户吗？');
				        break;
			    }
			   
			  });

		});
	</script>
</body>
</html>